package com.itheima;

public class Student implements Comparable<Student> {
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Student() {
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    @Override
    public int compareTo(Student o) {
        //按照学生年龄进行正序排序（当前学生的年龄-被比较学生的年龄）
        //this 代表当前对象
        //return this.getAge() - o.getAge();
        //按照学生年龄进行倒序排序（被比较学生的年龄-当前学生的年龄）
        return o.getAge() - this.getAge();
    }
}
